package collection;

import java.util.*;

/**
 * 可以用更简洁的代码实现匿名内部类
 */
public class LambdaDemo {
    public static void main(String[] args) {
        List<String> list = new ArrayList();
//        Collections.sort(list, new Comparator<String>() {
//            @Override
//            public int compare(String o1, String o2) {
//                return o1.length() - o2.length();
//            }
//        });
        //Lambda表达式写法
        Collections.sort(list, (String o1, String o2) -> {
            return o1.length() - o2.length();
        });
        Collections.sort(list, (o1, o2) -> {
            return o1.length() - o2.length();
        });
        Collections.sort(list, (o1, o2) ->o1.length() - o2.length());
        System.out.println(list);
    }
}
